﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    public class StockInTypeDAL:IStockInTypeDAL
    {

        #region IStockInTypeDAL 成员


        public IDataReader Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockInType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message); 
                throw;
            }
        }

        public DataTable SelectAll()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_StockInType_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public IDataReader Select(int StockInTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_StockInType_Select", new SqlParameter[] { new SqlParameter("@StockInTypeNum", StockInTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }      
        }

        public IDataReader Select(string StockInTypeName)
        {
            try
            {
                return SqlDbHelper.RunSQL_Reader(ConnectionString.ConnString, "select * from stock_in_type where stock_in_type_name=@StockInTypeName", new SqlParameter[] { new SqlParameter("@StockInTypeName", StockInTypeName) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string StockInTypeName, string StockInTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInTypeName",StockInTypeName),
                    new SqlParameter("@StockInTypeCode",StockInTypeCode)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockInType_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
                
        }

        public int Update(int StockInTypeNum, string StockInTypeName, string StockInTypeCode)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@StockInTypeNum",StockInTypeNum),
                    new SqlParameter("@StockInTypeName",StockInTypeName),
                    new SqlParameter("@StockInTypeCode",StockInTypeCode)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockInType_Update", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }              
        }

        public int Delete(int StockInTypeNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_StockINType_Delete", new SqlParameter[] { new SqlParameter("@StockInTypeNum", StockInTypeNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }      
        }

        #endregion
    }
}
